#include "SettingManager.h"

SettingManager *SettingManager::ultimoSM = NULL;

SettingManager *SettingManager::getSettingManager()
{
    return SettingManager::ultimoSM;
}

SettingManager::SettingManager() : settings("PalasSoft", "netim")
{
	alias = settings.value("alias", QString("")).toString();
	path_rsa = settings.value("path_rsa", QString("")).toString();
	path_agn = settings.value("path_agn", QString("")).toString();
	first_time = settings.value("first", true).toBool();
	settings.setValue("first", false);
        SettingManager::ultimoSM = this;
}

// This function tells if the inserted info is valid or blank.
// If it is valid also saves the info. If last two options are blank
// generate the info and save.
bool SettingManager::valid_or_null(initialsettings *initdialog)
{
	alias = initdialog->alias;
	path_rsa = initdialog->path_rsa;
	path_agn = initdialog->path_agn;
	// Check if alias is valid and not null
	if ((initdialog->alias.isNull()) ||
		(initdialog->alias.isEmpty()))
			return false;
	// Check if the certificate is valid or null if not ret false
	// Check if the agenda is valid or null if not ret false
	return true;
}

// This function telss if the info is valid and not blank.
// If it is valid also saves the info.
bool SettingManager::valid()
{
	// Check if alias is valid
	if ((alias.isNull()) ||	(alias.isEmpty()))
		return false;
	// Check if the certificate is valid if not return false
	// Check if the agenda is valid if not return false
	return true;
}

void SettingManager::Save()
{
        settings.setValue("alias", alias);
        settings.setValue("path_rsa", path_rsa);
        settings.setValue("path_agn", path_agn);
}

SettingManager::~SettingManager()
{
	settings.setValue("alias", alias);
	settings.setValue("path_rsa", path_rsa);
	settings.setValue("path_agn", path_agn);
}

